﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CodeBox.FB.DataAccess;
using CodeBox.FB.ViewModels;

namespace FBxMVC4.Controllers
{
    public class TeamController : Controller
    {

        TeamDataAccess teamDA;

        // GET: /Team/{teamName}
        public ActionResult MyTeam(string teamName)
        {
            teamDA = new TeamDataAccess();
            var players = teamDA.Players(teamName, 1);
            return View(players);
        }

        // GET: /Team/TeamInfo/{teamName}

        public JsonResult TeamInfo(string teamName)
        {
            teamDA = new TeamDataAccess();
            return Json(new TeamDataAccess().TeamInfo(teamName), JsonRequestBehavior.AllowGet);
        }


        public ActionResult New()
        {
            return View();
        }

        //  /TEAM/New

        [HttpPost]
        public ActionResult New(TeamInfoModel team)
        {
            teamDA = new TeamDataAccess();
            if (teamDA.Update(team))
                return View(team);
            else
                return View(team);
        }
    }
}
